<?php


namespace App\Utils;


class RandomUtil
{
    private const CHARACTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    private const CHAR_LETTER = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    private const CHAR_INT = '0123456789';

    /**
     * @param int $length
     * @return string
     */
    static function random($length = 6): string
    {
        $s = '';
        for ($i = 0; $i < $length; $i++) {
            $s .= self::CHARACTERS[rand(0, strlen(self::CHARACTERS) - 1)];
        }
        return $s;
    }

    /**
     * @param int $length
     * @return string
     */
    static function randomLetter($length = 6): string
    {
        $s = '';
        for ($i = 0; $i < $length; $i++) {
            $s .= self::CHAR_LETTER[rand(0, strlen(self::CHAR_LETTER) - 1)];
        }
        return $s;
    }

    /**
     * @param int $length
     * @return string
     */
    static function randomInt($length = 4): string
    {
        $s = '';
        for ($i = 0; $i < $length; $i++) {
            $s .= self::CHAR_INT[rand(0, strlen(self::CHAR_INT) - 1)];
        }
        return $s;
    }
}